/**
 * Created by x on 17-8-7.
 */
angular.module('tribalc').controller('smartDetailContorller',['$scope','$rootScope','Api','Alert','$state','$stateParams',function ($scope,$rootScope,Api,Alert,$state,$stateParams) {
    $scope.apartmentId = $stateParams.apartmentId;
    //$scope.setupDoor=setupDoor;
    $scope.showSmart = false;
    $scope.showNoSmart = false;
    $scope.getNetStatus = getNetStatus;
    $scope.getDoorType =  getDoorType;
    getLockInfoList();
    $scope.lockinfo ={}

    function confirmStatus(lockListInfo){
        console.log(lockListInfo)
        $scope.lockinfo = lockListInfo.data;
        if(lockListInfo.data.sn !== null){
            getlockinfo();
            function getlockinfo() {
                Api.getLcokInfo($scope.apartmentId,lockListInfo.data.sn,function (result) {
                    $scope.lockinfo.sn = result.data.sn;
                    $scope.lockinfo.electric = result.data.electric;
                    $scope.lockinfo.state = result.data.state;

                });
            }
        }
    }
    function getNetStatus(status){
        return {0:'已联网',1:'未联网'}[status];
    }

    function getDoorType(type){
        return {1:'大门锁',2:'内门锁'}[type];
    }

    function getLockInfoList() {
        Api.getLockInfoList($scope.apartmentId,function (result) {
            if(result.code == 404){
                return setupEquipment(null);
            }
            if(result.code == 200){
                setupEquipment(result);
                confirmStatus(result);
            }

        });
    }

    function setupEquipment(result) {
        if(result !== null){
            $scope.showSmart = true;
            $scope.showNoSmart=false;
        }else if(result === null){
            $scope.showNoSmart=true;
            $scope.showSmart = false;
        }
    }
}]);
